package org.example.multiThreading.creationThreads;

public class MyRunnable {
    public static void main(String[] args) {
        //使用实现Runnable接口创建线程
        TestMyRunnable myRunnable = new TestMyRunnable();
        //需要创建Thread对象
        Thread thread = new Thread(myRunnable);
        //启动线程
        thread.start();
        //使用匿名内部类创建
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName()+"-"+i);
                }
            }
        };
        //创建Thread对象
        Thread thread1 = new Thread(runnable);
        thread1.start();
    }
}

class TestMyRunnable implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+"-"+i);
        }
    }
}
